package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.dao.CustomerReturnListDao;
import com.atguigu.jxc.dao.UserDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.CustomerReturnListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qingyu
 * @create 2022-01-03 13:19
 * @description
 */
@Service
public class CustomerReturnListServiceImpl implements CustomerReturnListService {

    @Autowired
    private CustomerReturnListDao customerReturnListDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private CustomerDao customerDao;


    /**
     * 客户退货单查询（可查询条件：退货单号、客户、退款状态）
     * @param returnNumber
     * @param customerId
     * @param state
     * @param sTime
     * @param eTime
     * @return
     */
    @Override
    public List<CustomerReturnList> list(String returnNumber, Integer customerId, Integer state, String sTime, String eTime) {
        List<CustomerReturnList> customerReturnLists =  customerReturnListDao.list(returnNumber,customerId,state);
        customerReturnLists.forEach(customerReturnList -> {
            Integer customerIdDb = customerReturnList.getCustomerId();
            Integer userId = customerReturnList.getUserId();
            Customer customer = customerDao.getCustomerById(customerIdDb);
            User user = userDao.getUserById(userId);
            customerReturnList.setCustomerName(customer.getCustomerName());
            customerReturnList.setTrueName(user.getTrueName());
        });
        return customerReturnLists;
    }
}
